package service

import (
	"gin-ranking/api/auth/dao"
	"gin-ranking/common/result"
	"gin-ranking/common/util"
)

// IUserSessionService 定义接口
type IUserSessionService interface {
	ValidateToken(token string) // 检验token
}

type IUserSessionServiceImpl struct{}

// ValidateToken 校验token
func (IUserSessionServiceImpl) ValidateToken(token string) {

	// 判断用户是否存在
	userSessionVo := dao.UserSessionDao{}.GetByToken(token)
	if len(userSessionVo.UserId) < 1 {
		panic(result.FailEnum(result.CodeMsg402))
	}
	between := util.Between(util.CurrentTime(), userSessionVo.ExpiresTime.Time, util.Second)
	if between >= 0 {
		panic(result.FailEnum(result.CodeMsg403))
	}

}

var userSessionService = IUserSessionServiceImpl{}

func UserSessionService() IUserSessionService {
	return &userSessionService
}
